package com.decoration.basic.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.decoration.basic.entity.DecorationUser;
import com.decoration.basic.mapper.DecUserMapper;
import com.decoration.basic.findCondition.DecUserFindCondition;
import com.decoration.basic.service.DecUserService;
import com.decoration.basic.util.SnowFlake;

@Service("DecUserService")
public class DecUserServiceImpl implements DecUserService {

	@Resource
	private DecUserMapper decMapper;

	@Override
	public List<DecorationUser> findAll() {
		List<DecorationUser> list = decMapper.findAll();
		return list;
	}

	@Override
	public Boolean delete(String id) throws DataAccessException {
		// decMapper.delete(id);
		int num = decMapper.delete(id);
		return num == 1 ? Boolean.TRUE : Boolean.FALSE;
	}

	@Override
	public Boolean update(DecorationUser user) throws DataAccessException {

		int num = decMapper.update(user);
		return num == 1;
	}

	@Override
	public Boolean add(DecorationUser user) throws DataAccessException {
		user.setUserId(SnowFlake.getInstance().getNewUuid());
		user.setCreateTime(new Date());
		user.setUpdateTime(new Date());
		// 新增用户信息
		int num = 0;
		try {
			num = decMapper.add(user);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return false;
		}
		System.out.println(num);
		return num == 1;
	}

	@Override
	public DecorationUser findById(String id) {
		DecorationUser result = decMapper.findById(id);

		return result;
	}

	@Override
	public DecorationUser findByPhone(String userPhone) {

		DecorationUser result = decMapper.findByPhone(userPhone);
		return result;
	}

	@Override
	public Integer sumByPhone(String userPhone) {

		Integer result = decMapper.sumByPhone(userPhone);
		return result;
	}

	@Override
	public List<DecorationUser> getUserList(DecUserFindCondition findCondition) {
		return decMapper.getUserList(findCondition);
	}

	@Override
	public List<DecorationUser> getDesignUserList(DecUserFindCondition findCondition){
		return decMapper.getDesignUserList(findCondition);
	}

	@Override
	public int getUserSize(DecUserFindCondition findCondition) {
		int result = decMapper.getUserSize(findCondition);
		return result;
	}

	@Override
	public DecorationUser verifyUser(String userId) {
		return null;
	}
}
